package cn.syy.controller.app;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;
import cn.syy.pojo.domain.CustomerCar;
import cn.syy.pojo.dto.AddCarDto;
import cn.syy.result.R;
import cn.syy.service.ICustomerCarService;
import cn.syy.service.ICustomerService;
import com.aliyuncs.exceptions.ClientException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;


@Tag(name = "小程序乘客对象",description = "小程序乘客对象")
@RestController
@RequestMapping("/app/customer")
public class AppCustomerController {

    @Autowired
    public ICustomerService customerService;
    @Autowired
    private ICustomerCarService customerCarService;
    /**
     * 获取车辆信息
     */
    @Operation( summary= "获取车辆信息",description = "获取车辆信息接口")
    @GetMapping(value = "/car/list")
    public R<List<CustomerCar>> register() { //  @NotNull :JSR303参数校验不为空
        return R.success( customerCarService.list(new LambdaQueryWrapper<CustomerCar>()
                 .eq(CustomerCar::getCustomerId, StpUtil.getLoginIdAsLong())));
    }
    /**
     * 添加车辆信息
     */
    @Operation( summary= "添加车辆信息",description = "添加车辆信息接口")
    @Parameter(name = "openIdCode",description = "获取openId的code",required = true)
    @PostMapping(value = "/car/add")
    public R<Void> addCar(@RequestBody AddCarDto addCarDto) { //  @NotNull :JSR303参数校验不为空
        customerCarService.addCar(addCarDto);
        return R.success();
    }

    /**
     * 小程序乘客注册
     * */
    @Operation( summary= "获取小程序Customer",description = "小程序乘客对象获取接口")
    @Parameter(name = "openIdCode",description = "获取openId的code",required = true)
    @GetMapping(value = "/register/{openCodeId}")
    @SaIgnore
    public R<Void> register(@PathVariable("openCodeId") @NotNull String openIdCode) throws Exception { //  @NotNull :JSR303参数校验不为空
        customerService.register(openIdCode);
        return R.success();
    }

    /**
     * 小程序乘客注册包含手机号
     * */
    @Operation( summary= "获取小程序Customer包含手机号",description = "小程序Customer包含手机号对象获取接口")
    @Parameter(name = "openIdCodeAndPhoneCode",description = "获取openId的code和获取手机号的code",required = true)
    @GetMapping(value = "/register/{openCodeId}/{phoneCode}")
    @SaIgnore
    public R<Void> registerIncludePhoneCode(@PathVariable("openCodeId")String openIdCode ,@PathVariable("phoneCode") String phoneCode) throws ClientException { //  @NotNull :JSR303参数校验不为空
        customerService.registerIncludePhoneCode(openIdCode,phoneCode);
        return R.success();
    }

}
